<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>登录 | 学生管理系统 | 菜鸟基地</title>
</head>
<body>
    <div class="container">
        <div>
            <label for="login_acco">账号：</label>
            <input id="login_acco" type="text"/>
        </div>
        <div>
            <label for="login_password">密码：</label>
            <input id="login_password" type="password"/>
        </div>
        <div>
            <button id="login">登录</button>
        </div>
    </div>
</body>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<script>
    $(function(){
        $(document).keyup(function(event){
            if(event.keyCode == 13){
                $("#login").trigger("click");
            }
        });
        $("#login").click(function(){
            var login_acco = $.trim($("#login_acco").val());
            var login_password = $.trim($("#login_password").val());
            if(login_acco == ''){
                alert('账号不能为空！');
                // return;
            }
            else if(login_password == ''){
                alert('密码不能为空！');
                // return;
            }
            else {
                $.post('/api/login',{
                    'login_acco':login_acco,
                    'login_password':login_password
                },function(res) {
                    if (res.code !== 1) {
                        alert(res.msg);
                        return;
                    }
                    else{
                        alert("欢迎" + res.data.name + "登录成功！");
                        // alert("登录成功！")
                        window.location.href = '/students';
                    }
                });
            }
        });    
    });
</script>
</html>